//
//  AppDelegate+GJSetting.m
//  xmgjAppFront
//
//  Created by Zeki on 2020/7/27.
//  Copyright © 2020 guojutech. All rights reserved.
//

#import "AppDelegate+GJSetting.h"
#import <AMapFoundationKit/AMapFoundationKit.h>
#import <React/RCTLinkingManager.h>
#import <AlipaySDK/AlipaySDK.h>
#import "WXApi.h"
#import "GJWXPayManager.h"
#import "OpenInstallSDK.h"
// 百度人脸
#import "IDLFaceSDK/IDLFaceSDK.h"
#import "FaceParameterConfig.h"
@interface AppDelegate ()<OpenInstallDelegate>

@end

@implementation AppDelegate (GJSetting)
- (void)amapSetting{
  [AMapServices sharedServices].apiKey = GJAMapApiKey;
  [AMapServices sharedServices].enableHTTPS = YES;
}
- (void)initlizations{
  //版本更新检查
//  [GJUtil checkVersion:^(BOOL showToast) {
//
//  }];
  //路由
  [GJRouter loadConfigPlist:nil];
  //openinstall
  [OpenInstallSDK initWithDelegate:self];
  // 百度人脸
  NSString* licensePath = [NSString stringWithFormat:@"%@.%@", FACE_LICENSE_NAME, FACE_LICENSE_SUFFIX ];
  
  [[FaceSDKManager sharedInstance] setLicenseID:FACE_LICENSE_ID andLocalLicenceFile:licensePath andRemoteAuthorize:true];
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
  //处理通过openInstall URL Scheme唤起App的数据
  [OpenInstallSDK handLinkURL:url];
  
  if ([url.host isEqualToString:@"safepay"]) {
    //跳转支付宝钱包进行支付，处理支付结果
    [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
      GJLog(@"result aliPay = %@",resultDic);
      NSMutableDictionary *dic = [NSMutableDictionary dictionary];
      if ([resultDic[@"resultStatus"] intValue] == 9000) {
        [dic setValue:@"1" forKey:@"status"];
      }else{
        [dic setValue:@"0" forKey:@"status"];
      }
      //支付成功
       [[NSNotificationCenter defaultCenter] postNotificationName:GJKPayResultNotification object:nil userInfo:dic];
    }];
  }else{
    [RCTLinkingManager application:[UIApplication sharedApplication] openURL:url options:options];
  }
  [WXApi handleOpenURL:url delegate:[GJWXPayManager sharedManager]];
  return YES;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler{
    //处理通过openinstall一键唤起App时传递的数据
    [OpenInstallSDK continueUserActivity:userActivity];
    //其他第三方回调；
     return YES;
}
#pragma mark -- OpenInstallDelegate
- (void)getWakeUpParams:(OpeninstallData *)appData{
  if (appData.data) {//(动态唤醒参数)
      //e.g.如免填邀请码建立邀请关系、自动加好友、自动进入某个群组或房间等
  }
  if (appData.channelCode) {//(通过渠道链接或二维码唤醒会返回渠道编号)
      //e.g.可自己统计渠道相关数据等
  }
  GJLog(@"OpenInstallSDK:\n动态参数：%@;\n渠道编号：%@",appData.data,appData.channelCode);
}
@end
